<template>
  <view class="flex-col page">
    <view class="flex-col group">
      <view class="justify-between section_4" @click="setshowAddress">
        <view class="flex-col" style="width: 95%">
          <view class="flex-row group_8">
            <image src="../../static/images/dw.png" class="image_5" />
            <text v-if="address_info.tel" class="text_9"
              >{{ address_info.province }}{{ address_info.city
              }}{{ address_info.district }}{{ address_info.address }}</text
            >
            <text v-if="!address_info.tel" class="text_9">请选择地址</text>
          </view>
          <view class="flex-row group_9">
            <text>{{ address_info.realname }}</text>
            <text class="text_11">{{ address_info.tel }}</text>
          </view>
        </view>
        <image src="../../static/images/left.png" class="image_1 image_7" />
      </view>
      <view class="flex-col group_3" style="flex-shrink: 0">
        <view class="flex-row section_2">
          <view
            class="flex-col section_3"
            :style="{ backgroundImage: `url(${serve_info.cover})` }"
          >
          </view>
          <view class="flex-col group_4">
            <text class="text_4">{{ serve_info.name }}</text>

            <view class="flex-row group_6">
              <image
                src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844603803770493.png"
                class="image_4"
              />
              <text class="text_7">时长{{ serve_info.duration }}分钟</text>
            </view>
          </view>
          <view class="flex-col group_10 red itemprice">
            {{ serve_info.price }}元
          </view>
        </view>

        <view class="section_5 justify-between">
          <view class="left-group flex-row">
            <text class="text_12">服务技师</text>
          </view>
          <view class="flex-row group_10">
            <text>{{ technician.realname }}</text>
          </view>
        </view>
        <view class="section_5 justify-between" @click="timeClick">
          <view class="left-group flex-row">
            <text class="text_12">服务时间</text>
          </view>
          <view class="flex-row group_11">
            <text>{{ service_time }}</text>
            <image
              src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844611732717437.png"
              class="image_1 image_11"
            />
          </view>
        </view>

        <view class="section_5 justify-between">
          <view class="left-group flex-row">
            <text class="text_12">车费</text>
          </view>
          <view class="flex-row group_10 red">
            <text>{{ kilometreValue }}元</text>
          </view>
        </view>
        <view class="flex-col section_6">
          <view class="justify-between">
            <text class="text_20">
              全程共<text class="text_tips">{{ kilometre }}公里</text
              >,预计用时<text class="text_tips"
                >{{ tripTime.days > 0 ? tripTime.days + "天" : ""
                }}{{ tripTime.hours > 0 ? tripTime.hours + "小时" : ""
                }}{{
                  tripTime.minutes > 0 ? tripTime.minutes + "分钟" : ""
                }}</text
              >，打车出行收取来回车费。计费方式为出租车出行！
            </text>
          </view>
        </view>

        <view
          class="section_5 justify-between"
          v-show="couponList.length"
          @click="showPopup = true"
        >
          <view class="left-group flex-row">
            <image
              src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844608789159711.png"
              class="image_5"
            />
            <text class="text_12">优惠券</text>
          </view>
          <view class="flex-row group_16">
            <view
              class="flex-col items-center text-wrapper_5"
              v-if="popup_info.name"
            >
              <text>{{ popup_info.name }}</text>
            </view>
            <view style="color: #999; font-size: 28rpx" v-if="!popup_info.name"
              >请选择</view
            >
            <image
              src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844611732717437.png"
              class="image_1 image_14"
            />
          </view>
        </view>
        <view class="section_8 justify-between">
          <view class="flex-row group_17">
            <!-- <image
							src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844611130353859.png"
							class="image_5" /> -->
            <text class="text_26">订单备注</text>
          </view>
          <view class="flex-row group_18" @click="messageClick">
            <text class="text1" v-if="messageValue">{{ messageValue }}</text>
            <text class="text1" v-else>选填</text>
            <image
              src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844611732717437.png"
              class="image_1 image_16"
            />
          </view>
        </view>
        <!--支付方式start-->
        <view class="paytype">
          <radio-group @change="radioChange">
            <label class="item">
              <view class="title">
                <view class="title-item">
                  <image
                    src="../../static/images/b17.png"
                    class="image_5"
                  ></image>
                  余额支付(余额:￥{{ Number(user.balance) }})
                </view>
                <view class="title-desc">
                  <navigator class="rechage" url="/bundle/pages/wallet/wallet"
                    >充值返现</navigator
                  >
                </view>
              </view>
              <view class="riado">
                <radio value="账户余额" color="rgb(56, 152, 124)" />
              </view>
            </label>
            <label class="item">
              <view class="title">
                <view class="title-item">
                  <image
                    src="https://codefun-proj-user-res-1256085488.cos.ap-guangzhou.myqcloud.com/61ab188e1f655f0011bbaece/61e7d9270c0e3200129ec72c/16425844612334581390.png"
                    class="image_5"
                  ></image>
                  微信支付
                </view>
              </view>
              <view class="riado">
                <radio value="微信支付" checked color="rgb(56, 152, 124)" />
              </view>
            </label>
          </radio-group>
        </view>
      </view>
    </view>
    <view class="confirm_btn">
      <view class="justify-between section_12">
        <view class="flex-col">
          <view class="flex-row">
            <text class="text_36">合计</text>
            <view class="group_26">
              <text class="text_37"
                >￥{{
                  Number(serve_info.price) * vip_discount +
                  Number(kilometreValue) -
                  Number(poupon_price)
                }}</text
              >
              <text class="text_38"></text>
            </view>
          </view>
          <text class="text_39"
            >已优惠{{
              poupon_price +
              (Number(serve_info.price) -
                Number(serve_info.price) * vip_discount)
            }}元</text
          >
        </view>

        <view>
          <view
            class="flex-col items-center text-wrapper_6"
            @tap.stop="onMultClick(submit)"
            v-if="isPay == true"
          >
            <text>立即支付</text>
          </view>
          <view
            class="flex-col items-center text-wrapper_6"
            style="background-color: rgb(189, 255, 222)"
            v-else
          >
            <text>支付中……</text>
          </view>
        </view>
      </view>
    </view>
    <!--留言-->
    <u-popup :show="message" @close="close" :round="30" :closeable="true">
      <view style="height: 500rpx; padding: 80rpx 30rpx">
        <u--textarea
          placeholder="请输入内容"
          border="surround"
          clearable
          count
          maxlength="200"
          height="120"
          v-model="messageValue"
        ></u--textarea>
        <u-button
          text="保存"
          color="#18b567"
          　style="width: 40%;margin: 30rpx auto;"
          @click="messageSave"
        >
        </u-button>
      </view>
    </u-popup>
    <!--留言end-->
    <!--预约时间-->
    <u-popup
      :show="time"
      :closeable="true"
      @close="close"
      :round="30"
      bgColor="#18B567"
      closeColor="#ffffff"
    >
      <view class="time-head">
        <view class="title">选择服务时间</view>
        <week-time
          @back="changeBack"
          @changeServiceTime="changeServiceTime"
          :id="technician_id"
          :addtime="servAddtime"
          :technician_start_time="technician_start_time"
          :technician_end_time="technician_end_time"
          :serverTime="serve_info.duration"
        >
        </week-time>
      </view>
    </u-popup>
    <!--预约时间end-->

    <!-- 选择优惠券 -->
    <u-popup :show="showPopup" :closeable="true" @close="close1">
      <view class="popup">
        <view class="popup-header">
          <text>优惠券领取</text>
        </view>

        <view class="content">
          <scroll-view
            scroll-y="true"
            style="height: 710rpx"
            scroll-with-animation="true"
          >
            <view
              class="item flex"
              v-for="(item, index) in couponList"
              :key="index"
              @click="selectPopup(item)"
              >　
              <view class="left">
                <view class="num">
                  ¥
                  <text>{{ item.money }}</text>
                </view>
                <view class="condition">
                  {{ item.name }}
                </view>
              </view>
              <view class="right flex">
                <view class="circular">
                  <view
                    class="circular-item"
                    v-for="(item, index) in ['', '', '', '']"
                    :key="index"
                  >
                  </view>
                </view>
                <view class="explain">
                  <view class="title"> 店铺优惠券</view>
                  <view class="details">有效期至{{ item.end_time }}</view>
                </view>
              </view>
            </view>
          </scroll-view>
        </view>
      </view>
    </u-popup>

    <u-popup
      :show="showAddress"
      :round="10"
      mode="bottom"
      :closeable="true"
      @close="showAddress = fasle"
    >
      <view class="popup">
        <view class="popup-header">
          <text>选择服务地址</text>
        </view>
        <view class="content1" v-if="addressList.length > 0">
          <u-radio-group
            v-model="addressValue"
            placement="row"
            @change="groupChange"
          >
            <scroll-view
              scroll-y="true"
              style="height: 710rpx"
              scroll-with-animation="true"
            >
				<view 
					class="item flex justify-between" 
					v-for="(item, index) in addressList"
					:key="index"
					@click="selectAddress(index, item)"
				>
					<view class="flex">
						<view class="left" style="padding-right: 3px;">
						  <u-radio
						    shape="circle"
						    :key="index"
						    :name="item.id"
						    activeColor="#18B567"
						    @change="selectAddress(index, item)"
						  ></u-radio>
						</view>
						<view class="center">
							<view class="circular">
							  {{ item.district }}{{ item.address }}
							</view>
							<view class="explain">
							  {{ item.realname }} : {{ item.mobile }}
							</view>
						</view>
					</view>
					<view class="rigth" @click="editAddress(item)">
					  <image src="../../static/images/edit.png"></image>
					</view>
				</view>
            </scroll-view>
          </u-radio-group>
        </view>
        <view v-else>
          <zNo toast="请先添加您的服务地址"></zNo>
        </view>
      </view>
      <view
        style="width: 80%; margin: 0 auto; padding-bottom: 10rpx"
        @click="add"
      >
        <u-button
          type="primary"
          text="新增地址"
          shape="circle"
          color="#18B567"
        ></u-button>
      </view>
    </u-popup>
  </view>
</template>

<script>
import zNo from "@/components/z-no/index.vue";
import weekTime from "@/components/weeks-calendars/weekTime.vue";
import { blancePay } from "@/utils/index.js";
export default {
  components: {
    weekTime,
    zNo,
  },
  data() {
    return {
      DistanceIs: {},
      tripTime: {
        days: 0,
        hours: 0,
        minutes: 0,
        seconds: 0,
        time: 0,
      },
      servAddtime: 0,
      addressValue: 0,
      isPay: true,
      checked: false,
      couponList: [],
      showPopup: false,
      checkboxValue1: ["本人已同意"],
      // 基本案列数据
      checkboxList1: [
        {
          name: "本人已同意",
          disabled: false,
          checked: true,
        },
      ],
      message: false, //留言弹出
      messageValue: "", //留言内容
      time: false, //预约弹出
      timeValue: "2021-10-1", //预约时间
      radioValue: false,
      travelTypeValue: 1,
      payList: [
        {
          name: "账户余额",
        },
        {
          name: "微信支付",
        },
      ],
      payType: "微信支付",
      id: "",
      serve_info: {
        id: "",
        name: "",
        price: "",
        cover: "",
        discount: "",
        sales: 0,
        praise: "",
        duration: "",
        coupon: 1,
      },
      technician: {
        realname: "",
      },
      address_info: {
        id: "",
        realname: "",
        mobile: "",
        province: "",
        city: "",
        district: "",
        address: "",
        is_default: 0,
      },
      valuation: [
        {
          kilometre: 0,
        },
      ],
      user: {
        id: 0,
        is_vip: 0,
        balance: null,
        vip_discount: "0",
      },
      message: false,
      service_time: "",
      poupon_price: 0,
      available: [], //优惠券
      coupon_id: 0,
      appointment_time_t: "",
      appointment_time_y: "",
      popup_info: {
        id: 0,
        name: "",
        money: "",
        discount: "",
        condition: "",
        type: 0,
        service_id: 0,
        start_time: "",
        end_time: "",
        reason: "",
        address_id: "",
        technician_lat: "",
        technician_lng: "",
      },
      kilometre: "",
      kilometreValue: "",
      vip_discount: 1,
      technician_lng: 0,
      technician_lat: 0,
      technician_id: 0,
      technician_start_time: 0,
      technician_end_time: 0,
      payShow: false,
      weekType: "",
      showAddress: false,
      addressList: [],
      onClick: true,
      count: 0,
      order_time: null,
    };
  },
  watch: {
    address_info(newVal, oldVal) {
      if (newVal.id) {
        this.address_id = newVal.id;
        this.getDistance();
      }
    },
    appointment_time_t() {
      this.meetsDay();
    },
  },
  onLoad(options) {
    this.id = options.id;
  },
  onShow() {
	  // uni.removeStorageSync("recharge_sn");
    const sn = uni.getStorageSync("recharge_sn");
    if (sn) {
      this.checkOrderStatus(sn, "order");
      return;
    }
    let date = new Date();
    this.appointment_time_y =
      date.getFullYear() +
      "-" +
      this.fill(Number(date.getMonth()) + 1) +
      "-" +
      this.fill(date.getDate());
    this.init();
  },
  methods: {
    numFilter(value) {
      // 截取当前数据到小数点后两位
      let realVal = parseFloat(value).toFixed(2);
      return realVal;
    },
    async checkOrderStatus(order_sn, form) {
      const res = await this.$http.post("api/wxapp/check_order_status", {
        order_sn,
        form,
      });
      // 跳转订单列表
      uni.switchTab({
        url: "/pages/order/order",
      });
      uni.removeStorageSync("recharge_sn");
    },
    groupChange(n) {
      this.showAddress = false;
    },
    editAddress(item) {
      uni.navigateTo({
        url:
          "/bundle/pages/address_edit/address_edit?id=" +
          item.id +
          "&type=order",
      });
    },
    selectAddress(index, address_info) {
      this.addressValue = address_info.id;
      this.showAddress = false;
      let tel = address_info.mobile;
      address_info.tel = tel.slice(0, 3) + "****" + tel.slice(7);
      this.address_info = address_info;
    },
    add() {
      uni.navigateTo({
        url: "/bundle/pages/address_edit/address_edit?type=order",
      });
    },
    setshowAddress() {
      this.showAddress = true;
      this.getAddress();
    },
    getAddress() {
      this.$http.post("api/address/index").then((res) => {
        this.addressList = res;
      });
    },
    // 判断属于白天还是晚上
    meetsDay() {
      if (!this.appointment_time_t) {
        this.weekType = "";
      }
      let arr = this.appointment_time_t.split(":");

      if (arr[0] >= 8 && arr[0] <= 20) {
        this.weekType = "day";
      } else {
        this.weekType = "night";
      }
    },
    toweb() {
      uni.navigateTo({
        url: "/bundle/pages/web/web?title=user_instructions",
      });
    },
    getchecked(e) {
      this.checked = e;
    },
    selectPopup(item) {
      this.popup_info = item;
      let price = this.serve_info.price;
      this.coupon_id = item.id;
      if (item.type === 1) {
        // 折扣券
        this.poupon_price = (price * (10 - Number(item.discount))) / 10;
      } else {
        // 满减券
        this.poupon_price = item.money;
      }
	  
	  const money = Number(this.serve_info.price) * this.vip_discount +
                  Number(this.kilometreValue) -
                  Number(this.poupon_price)
	  
	  let order_info = uni.getStorageSync("order_info");
	  order_info.pay_money = money
	  uni.setStorageSync("order_info", order_info);

      this.showPopup = false;
    },
    fill(a) {
      return 10 > a ? "0" + (0 | a) : a;
    },
    close1() {
      this.showPopup = false;
    },
    changeServiceTime(e) {
      this.service_time = e.time;
      let arr = e.time.split(" ");
      this.appointment_time_y = arr[0];
      this.appointment_time_t = arr[1];
      this.time = false;
    },
    init() {
      // 订单结算
      let order_info = uni.getStorageSync("order_info");
      let { service_id, spec_id, technician_id } = order_info;
      this.$http
        .post("api/order/settlement2", {
          service_id,
          spec_id,
          technician_id,
        })
        .then((res) => {
          let { service, technician, valuation, user } = res;
          this.serve_info = service;
          this.technician = technician;

          this.technician_lng = technician.lng;
          this.technician_lat = technician.lat;
          this.technician_id = technician.id;

          this.technician_start_time = technician.start_time;
          this.technician_end_time = technician.end_time;

          this.valuation = valuation;
          this.user = user;
          this.getDistance();
          // 获取优惠券
          this.$http
            .post("api/order/coupon", {
              service_id,
              money: service.price,
            })
            .then((res) => {
              let { available } = res;

              this.couponList = available;
            });
			
			order_info.pay_money =  this.serve_info.price
			uni.setStorageSync("order_info", order_info);
        });

      if (this.addressValue) {
        return;
      }
      // 获取地址列表
      this.$http.post("api/address/index").then((res) => {
        if (res.length) {
          for (let data of res) {
            if (data.is_default == 1) {
              let tel = data.mobile;
              data.tel = tel.slice(0, 3) + "****" + tel.slice(7);
              this.address_info = data;
              this.addressValue = data.id;
            }
          }
        }
      });
    },
    format(date) {
      let y = date.getFullYear();
      let m = date.getMonth() + 1;
      let d = date.getDate();
      return y + "-" + this.fill(m) + "-" + this.fill(d);
    },
    // 获取时间
    getTimeData(addtime) {
      // 获取当天是否存在结算时间
      let useTime = [];
      let cTime = this.format(new Date());

      // 	获取当前日期
      var date = new Date();
      //var date = new Date("12 11,2022 23:32:22")
      let nowTime =
        date.getFullYear() +
        "-" +
        this.fill(Number(date.getMonth()) + 1) +
        "-" +
        this.fill(date.getDate());
      let nowH = date.getHours();
      let nowF = date.getMinutes();
      let date_data =
        this.fill(Number(new Date().getMonth()) + 1) +
        "-" +
        this.fill(new Date().getDate());
      if (nowH == 23 && nowF >= 30) {
        let t = new Date(new Date().setDate(new Date().getDate() + 1));
        date_data = this.fill(t.getMonth() + 1) + "-" + this.fill(t.getDate());
        cTime = nowTime = this.format(t);
      }
      // 获取已用时间
      this.$http
        .post("api/order/dateList", {
          date: date_data,
          id: this.id,
          addtime,
        })
        .then((res) => {
          let start = this.technician_start_time;
          let end = this.technician_end_time;
          let computStart = Number(start / 2);
          let computEnd = Number(end / 2);
          for (let i = computStart; i <= computEnd; i += 0.5) {
            let d = i;
            if (Number.isInteger(d)) {
              d = d < 10 ? "0" + d + ":00" : d + ":00";
            } else {
              d = d < 10 ? "0" + parseInt(d) + ":30" : parseInt(d) + ":30";
            }
            var length = useTime.length;
            useTime.push({
              time: d,
              fullness: false,
              gayer: false,
            });

            res.forEach((item) => {
              if (item.hour === d) {
                useTime[length].fullness = true;
              }
            });

            var flgmin = 0;
            if (nowF > 30) {
              nowF > 45 ? (flgmin = 1) : (flgmin = 0.5);
            } else {
              nowF > 15 ? (flgmin = 0.5) : (flgmin = 0);
            }

            if (nowTime === cTime) {
              // 判断当前小时
              if (Number(i) <= nowH + flgmin) {
                useTime[length].gayer = true;
              } else {
              }
            }
          }

          var num = [];
          if (this.serve_info) {
            var serverTime = Math.ceil(this.serve_info.duration / 30);
          } else {
            var serverTime = 0;
          }
          for (let i = 0; i < useTime.length; i++) {
            if (useTime[i].fullness == false) {
              num.push(i);
            } else {
              if (num.length < serverTime && num.length > 0) {
                num.forEach((key) => {
                  useTime[key].fullness = true;
                });
              }
              num = [];
            }
          }
          for (let i = 0; i < useTime.length; i++) {
            if (nowH == 23 && nowF >= 30) {
              if (useTime[i].fullness === false) {
                this.service_time = nowTime + " " + useTime[i].time;
                this.appointment_time_t = useTime[i].time;
                break;
              }
            } else {
              if (useTime[i].gayer === false && useTime[i].fullness === false) {
                this.service_time = nowTime + " " + useTime[i].time;
                this.appointment_time_t = useTime[i].time;
                break;
              }
            }
          }
        });
    },
    //重新计算
    getDistance() {
      // 获取地址列表
      var that = this;
      if (this.technician_lat && this.address_id) {
        this.$http
          .post("api/order/getDistance2", {
            address_id: this.address_id,
            technician_id: this.technician_id,
          })
          .then((res) => {
            that.tripTime = res.duration;
            that.servAddtime = res.duration.time;
            // that.getTimeData(res.duration.time);
            that.kilometre = res.distance.toFixed(2); //距离
            that.kilometreValue = res.fare * 2;
            // 获取服务时间
            if (res.errmsg == null) {
              that.DistanceIs = {
                v: true,
                m: "",
              };
            } else {
              that.DistanceIs = {
                v: false,
                m: res.errmsg,
              };
              uni.showModal({
                content: res.errmsg,
                showCancel: false,
              });
            }
          });
      }
    },
    changeBack(t) {},
    radioChange(e) {
      this.appointment_time_y = e;
    },
    messageClick() {
      this.message = true;
    },
    timeClick() {
      this.time = true;
    },
    close() {
      this.message = false;
      this.time = false;
    },
    messageSave() {
      this.message = false;
    },
    travelType(e) {
      this.travelTypeValue = e;
      this.getDistance();
    },
    async submit() {
      if (!this.address_info.id) {
        uni.showToast({
          icon: "none",
          title: "请选择地址",
        });
        this.isPay = true;
        this.setshowAddress();
        return;
      }
      if (!this.appointment_time_t) {
        uni.showToast({
          icon: "none",
          title: "请选择服务时间",
        });
        this.isPay = true;
        this.timeClick();
        return;
      }
      if (!this.payType) {
        uni.showToast({
          icon: "none",
          title: "请选择支付方式",
        });
        this.isPay = true;
        return;
      }
      if (!this.DistanceIs.v) {
        uni.showModal({
          content: this.DistanceIs.m,
          showCancel: false,
        });
        return;
      }

      this.isPay = false;
      let order_info = uni.getStorageSync("order_info");
	  
      if (
        this.payType === "账户余额" &&
        order_info.pay_money > Number(this.user.balance)
      ) {
        uni.showToast({
          icon: "none",
          title: "账户余额不足",
        });
        this.isPay = true;
        return;
      }
	  
      order_info.address_id = this.address_info.id;
      order_info.remark = this.messageValue;

      order_info.pay_money =
        Number((Number(this.serve_info.price) * this.vip_discount).toFixed(2)) +
        Number(this.kilometreValue) -
        Number(this.poupon_price);
      order_info.fare = Number(this.kilometreValue);
      order_info.discount =
        this.poupon_price +
        Number(
          (
            Number(this.serve_info.price) -
            Number(this.serve_info.price) * this.vip_discount
          ).toFixed(2)
        );
      order_info.coupon_id = this.coupon_id;
      order_info.total_money =
        Number(this.serve_info.price) + Number(this.kilometreValue);
      order_info.appointment_time =
        this.appointment_time_y + " " + this.appointment_time_t;

      var order_sn = null;

      var ordRes = await this.$http
        .post("api/order/createOrder", order_info)
        .then((res) => {
          order_sn = res;
        })
        .catch((er) => {
          const errMsg = er.errMsg;
          uni.showToast({
            title: errMsg,
            icon: "none",
          });
          if (errMsg.indexOf("车费有误") != -1) {
            this.setshowAddress();
          }
          if (errMsg.indexOf("预约时间") != -1) {
            this.timeClick();
          }
          if (errMsg.indexOf("时间被占用") != -1) {
            this.timeClick();
          }
          this.isPay = true;
        });

      if (!order_sn) {
        return;
      }

      let pay_way = this.payType === "账户余额" ? 1 : 4;

      order_info.payType = this.payType;
      order_info.order_sn = order_sn;
      let date = new Date();
      let create_time =
        date.getFullYear() +
        "-" +
        this.fill(Number(date.getMonth()) + 1) +
        "-" +
        this.fill(date.getDate()) +
        " " +
        this.fill(date.getHours()) +
        ":" +
        this.fill(date.getMinutes()) +
        ":" +
        this.fill(date.getDate());
      order_info.create_time = create_time;
      uni.setStorageSync("order_info", order_info);

      if (pay_way === 1) {
        // 余额支付
        uni.showLoading({
          title: "支付中...",
        });
        blancePay({
          order_sn,
          pay_way,
          form: "order",
        });
      } else {
        // 小程序支付
        uni.setStorageSync("recharge_sn", order_sn);
        this.$http
          .post("api/pay/pay", { order_sn, pay_way, form: "order" })
          .then((res) => {
            // plus.runtime.openURL(res.url_link);
			uni.redirectTo({
				url: `/pages/confirm_order/url_link?url=${res.url_link}&navi=${1}&form=order`,
			})
          });
      }
    },
    radioChange(e) {
      const v = e.detail.value;
      this.payType = v;
    },
  },
};
</script>

<style scoped lang="scss">
@import "index.scss";
</style>
